﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyThuVien.DAL
{
    class daoSach
    {
        Connection connect = new Connection();

        public bool SuaSach(String MaSach, String TenSach, String TacGia, String NhaXuatBan)
        {
            SqlParameter[] Parameters = new SqlParameter[4];
            Parameters[0] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaSach;
            Parameters[1] = new SqlParameter("@TenSach", SqlDbType.NVarChar, 50);
            Parameters[1].Value = TenSach;
            Parameters[2] = new SqlParameter("@TacGia", SqlDbType.NVarChar, 50);
            Parameters[2].Value = TacGia;
            Parameters[3] = new SqlParameter("@NhaXuatBan", SqlDbType.NVarChar, 50);
            Parameters[3].Value = NhaXuatBan;
            return connect.executeUpdateProcedureQuery("SuaSach", Parameters);
        }

        public bool ThemSach(String MaSach, String TenSach, String TacGia, String NhaXuatBan)
        {
            SqlParameter[] Parameters = new SqlParameter[4];
            Parameters[0] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaSach;
            Parameters[1] = new SqlParameter("@TenSach", SqlDbType.NVarChar, 50);
            Parameters[1].Value = TenSach;
            Parameters[2] = new SqlParameter("@TacGia", SqlDbType.NVarChar, 50);
            Parameters[2].Value = TacGia;
            Parameters[3] = new SqlParameter("@NhaXuatBan", SqlDbType.NVarChar, 50);
            Parameters[3].Value = NhaXuatBan;
            return connect.executeInsertProcedureQuery("ThemSach", Parameters);
        }

        public bool XoaSach(String MaSach)
        {
            SqlParameter[] Parameters = new SqlParameter[1];
            Parameters[0] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaSach;
            return connect.executeDeleteProcedureQuery("XoaSach", Parameters);
        }

        public DataTable TimSach(String MaSach, String TenSach, String TacGia, String NhaXuatBan)
        {
            SqlParameter[] Parameters = new SqlParameter[4];
            Parameters[0] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaSach;
            Parameters[1] = new SqlParameter("@TenSach", SqlDbType.NVarChar, 50);
            Parameters[1].Value = TenSach;
            Parameters[2] = new SqlParameter("@TacGia", SqlDbType.NVarChar, 50);
            Parameters[2].Value = TacGia;
            Parameters[3] = new SqlParameter("@NhaXuatban", SqlDbType.NVarChar, 50);
            Parameters[3].Value = NhaXuatBan;
            return connect.executeSelectProcedureQuery("TimSach", Parameters);
        }
    }
}
